//
//  MYTabBar.m
//  MYChatting
//
//  Created by mac on 16/7/18.
//  Copyright © 2016年 lhf. All rights reserved.
//

#import "MYTabBar.h"


@interface MYTabBar ()



@end

@implementation MYTabBar


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIButton *composeBtn = [[UIButton alloc] init];
        [composeBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [composeBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        [composeBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [composeBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        [composeBtn sizeToFit];
        [self addSubview:composeBtn];
        self.composeBtn = composeBtn;
//        [composeBtn addTarget:self action:@selector(composeBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}


//- (void)composeBtnClick{
//    
//}



- (void)layoutSubviews{
    [super layoutSubviews];
    
    CGFloat w = self.bounds.size.width / 5;
    CGFloat h = self.bounds.size.height;
    CGRect rect = CGRectMake(0, 0, w, h);
    NSInteger index = 0;
    for (UIView *childView in self.subviews) {
        
        if ([childView isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
           
            childView.frame = CGRectOffset(rect, index * w, 0);
            index += (index == 1 ? 2 : 1);
        }
    }
    
    self.composeBtn.frame = CGRectOffset(rect, 2 * w,0);
}

@end
